package com.weberror.frontendmonitoring.jsanomaly.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weberror.frontendmonitoring.jsanomaly.entity.Jsanomaly;
import com.weberror.frontendmonitoring.jsanomaly.service.JsanomalyService;
import com.weberror.frontendmonitoring.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * js异常(Jsanomaly)表控制层
 *
 * @author cnxym
 * @since 2022-08-16 13:06:13
 */
@RestController
@RequestMapping("/Error/JSError")
public class JsanomalyController{
    /**
     * 服务对象
     */
    @Autowired
    private JsanomalyService jsanomalyService;

    /**
     * 分页查询所有数据
     *
     * @param page      分页对象
     * @param jsanomaly 查询实体
     * @return 所有数据
     */
    @GetMapping
    public R selectAll(Page<Jsanomaly> page, Jsanomaly jsanomaly) {
        return R.OK().data("jsanomaly", jsanomalyService.page(page, new QueryWrapper<>(jsanomaly)));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("getError/JSError/{id}")
    public R selectOne(@PathVariable Integer id) {

        return R.OK().data("jsanomaly", jsanomalyService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param jsanomaly 实体对象
     * @return 新增结果
     */
    @PostMapping
    public R insert(@RequestBody Jsanomaly jsanomaly) {
        return R.OK().data("jsanomaly", jsanomalyService.save(jsanomaly));
    }
}

